/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import com.comac.ins.isfd.domain.bo.query.IsfdLoadQueryBo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.isfd.domain.vo.IsfdLoadVo;
import com.comac.ins.isfd.domain.bo.IsfdLoadBo;
import com.comac.ins.isfd.service.IIsfdLoadService;

/**
 * 载荷库
 *
 * @author lanlan
 * @date 2024-07-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/load")
public class IsfdLoadController extends BaseController {

    private final IIsfdLoadService isfdLoadService;

    /**
     * 查询载荷库列表
     */
    @SaCheckPermission("isfd:load:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdLoadVo> list(@RequestBody IsfdLoadQueryBo bo) {
        return isfdLoadService.queryPageList(bo);
    }

    /**
     * 导出载荷库列表
     */
    @SaCheckPermission("isfd:load:export")
    @Log(title = "载荷库功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdLoadQueryBo bo, HttpServletResponse response) {
        List<IsfdLoadVo> list = isfdLoadService.queryList(bo);
        ExcelUtil.exportExcel(list, "载荷库功能", IsfdLoadVo.class, response);
    }

    /**
     * 获取载荷库详细信息
     *
     * @param no 主键
     */
    @SaCheckPermission("isfd:load:query")
    @GetMapping("/{no}")
    public R<IsfdLoadVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Integer no) {
        return R.ok(isfdLoadService.queryById(no));
    }

    /**
     * 新增载荷库
     */
    @SaCheckPermission("isfd:load:add")
    @Log(title = "载荷库功能", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdLoadBo bo) {
        return toAjax(isfdLoadService.insertByBo(bo));
    }

    /**
     * 修改载荷库
     */
    @SaCheckPermission("isfd:load:edit")
    @Log(title = "载荷库功能", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdLoadBo bo) {
        return toAjax(isfdLoadService.updateByBo(bo));
    }

    /**
     * 删除载荷库
     *
     * @param nos 主键串
     */
    @SaCheckPermission("isfd:load:remove")
    @Log(title = "载荷库功能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{nos}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] nos) {
        return toAjax(isfdLoadService.deleteWithValidByIds(List.of(nos), true));
    }
}
